home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / 3dTruchet.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  8.1 KB  |  239 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ;
  17. ;    3dTruchet  - a script to create Truchet patterns
  18. ;                 by Adrian Likins <aklikins@eos.ncsu.edu>
  19. ;                 http://www4.ncsu.edu/~aklikins/
  20. ;    version about .8 give or take
  21. ;
  22. ;  Lots of thanks to Quartic for his help.
  23. ;
  24. ;
  25. ;         The utility of this script is left as an exercise for the reader.
  26.  
  27. (define (center-ellipse img
  28.                         cx
  29.                         cy
  30.                         rx
  31.                         ry
  32.                         op
  33.                         aa
  34.                         feather
  35.                         frad)
  36.   (gimp-ellipse-select img (- cx rx) (- cy ry) (+ rx rx) (+ ry ry)
  37.                        op aa feather frad)
  38. )
  39.  
  40. (define (use-tile img
  41.                   drawable
  42.                   height
  43.                   width
  44.                   img2
  45.                   drawable2
  46.                   xoffset
  47.                   yoffset)
  48.   (gimp-edit-copy drawable2)
  49.   (let (
  50.        (floating-sel (car (gimp-edit-paste drawable FALSE)))
  51.        )
  52.     (gimp-layer-set-offsets floating-sel xoffset yoffset)
  53.     (gimp-floating-sel-anchor floating-sel)
  54.   )
  55. )
  56.  
  57.  
  58. (define (create-tile img
  59.                      drawable1
  60.                      drawable2
  61.                      size
  62.                      thickness
  63.                      backcolor
  64.                      begincolor
  65.                      endcolor
  66.                      supersample)
  67.   (let* (
  68.         (half-thickness (/ thickness 2))
  69.         (outer-radius (+ (/ size 2) half-thickness))
  70.         (inner-radius (- (/ size 2) half-thickness))
  71.         )
  72.  
  73.     (gimp-selection-all img)
  74.     (gimp-context-set-background backcolor)
  75.     (gimp-edit-fill drawable1 BACKGROUND-FILL)
  76.  
  77.     (let* (
  78.           (tempSize (* size 3))
  79.           (temp-img (car (gimp-image-new tempSize tempSize RGB)))
  80.           (temp-draw (car (gimp-layer-new temp-img tempSize tempSize
  81.                                           RGB-IMAGE "Jabar" 100 NORMAL-MODE)))
  82.           (temp-draw2 (car (gimp-layer-new temp-img tempSize tempSize
  83.                                           RGB-IMAGE "Jabar" 100 NORMAL-MODE)))
  84.           )
  85.  
  86.       (gimp-image-undo-disable temp-img)
  87.       (gimp-image-add-layer temp-img temp-draw 0)
  88.       (gimp-image-add-layer temp-img temp-draw2 0)
  89.       (gimp-context-set-background backcolor)
  90.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  91.       (gimp-edit-fill temp-draw2 BACKGROUND-FILL)
  92.  
  93.       ;weird aint it
  94.       (gimp-context-set-background begincolor)
  95.       (gimp-context-set-foreground endcolor)
  96.  
  97.       (center-ellipse temp-img size size outer-radius outer-radius
  98.                       CHANNEL-OP-REPLACE TRUE FALSE 0)
  99.       (center-ellipse temp-img size size inner-radius inner-radius
  100.                       CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  101.  
  102.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius
  103.                       CHANNEL-OP-ADD TRUE FALSE 0)
  104.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius
  105.                       CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  106.  
  107.       (gimp-edit-blend temp-draw FG-BG-RGB-MODE NORMAL-MODE
  108.                        GRADIENT-SHAPEBURST-ANGULAR 100 0 REPEAT-NONE FALSE
  109.                        supersample 3 0.2 TRUE
  110.                        size size (* size 2) (/ size 2))
  111.  
  112.       (center-ellipse temp-img size (* size 2)  outer-radius outer-radius
  113.                       CHANNEL-OP-REPLACE TRUE FALSE 0)
  114.       (center-ellipse temp-img size (* size 2) inner-radius inner-radius
  115.                       CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  116.  
  117.       (center-ellipse temp-img (* size 2) size  outer-radius outer-radius
  118.                       CHANNEL-OP-ADD TRUE FALSE 0)
  119.       (center-ellipse temp-img (* size 2) size  inner-radius inner-radius
  120.                       CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  121.  
  122.       ;(gimp-edit-fill temp-img temp-draw2 BACKGROUND-FILL)
  123.  
  124.       (gimp-edit-blend temp-draw2 FG-BG-RGB-MODE NORMAL-MODE
  125.                        GRADIENT-SHAPEBURST-ANGULAR 100 0 REPEAT-NONE FALSE
  126.                        supersample 3 0.2 TRUE
  127.                        size size (* size 2) (* size 2))
  128.  
  129.       (gimp-selection-none temp-img)
  130.  
  131.       (gimp-image-resize temp-img size size (- size) (- size))
  132.       ; woo hoo it works....finally...
  133.  
  134.  
  135.       (gimp-selection-all temp-img)
  136.       (gimp-edit-copy temp-draw)
  137.       (let ((floating-sel (car (gimp-edit-paste drawable2 FALSE))))
  138.         (gimp-floating-sel-anchor floating-sel))
  139.  
  140.       (gimp-edit-copy temp-draw2)
  141.       (let ((floating-sel (car (gimp-edit-paste drawable1 FALSE))))
  142.         (gimp-floating-sel-anchor floating-sel))
  143.  
  144.       ;(let ((drawble (car (gimp-drawable-transform-flip-simple img drawable1
  145.       ;                     ORIENTATION-HORIZONTAL
  146.       ;                     TRUE 0 TRUE)))))
  147.  
  148.  
  149.       ;(gimp-display-new temp-img)
  150.       (gimp-image-delete temp-img)
  151.     )
  152.   )
  153. )
  154.  
  155.  
  156. (define (script-fu-3dtruchet size
  157.                              thickness
  158.                              backcolor
  159.                              begincolor
  160.                              endcolor
  161.                              supersample
  162.                              xtiles
  163.                              ytiles)
  164.   (let* (
  165.         (width (* size xtiles))
  166.         (height (* size ytiles))
  167.         (img (car (gimp-image-new width height RGB)))
  168.         (tile (car (gimp-image-new size size RGB)))
  169.         (layer-one (car (gimp-layer-new img width height
  170.                                         RGB-IMAGE "Rambis" 100 NORMAL-MODE)))
  171.         (tiledraw1 (car (gimp-layer-new tile size size
  172.                                         RGB-IMAGE "Johnson" 100 NORMAL-MODE)))
  173.         (tiledraw2 (car (gimp-layer-new tile size size
  174.                                         RGB-IMAGE "Cooper" 100 NORMAL-MODE)))
  175.         (Xindex 0)
  176.         (Yindex 0)
  177.         )
  178.  
  179.     (gimp-context-push)
  180.  
  181.     (gimp-image-undo-disable img)
  182.     (gimp-image-undo-disable tile)
  183.  
  184.     (gimp-image-add-layer img layer-one 0)
  185.     (gimp-image-add-layer tile tiledraw1 0)
  186.     (gimp-image-add-layer tile tiledraw2 0)
  187.  
  188.     ;just to look a little better
  189.     (gimp-selection-all img)
  190.     (gimp-context-set-background backcolor)
  191.     (gimp-edit-fill layer-one BACKGROUND-FILL)
  192.     (gimp-selection-none img)
  193.  
  194.     (create-tile tile tiledraw1 tiledraw2 size thickness
  195.                  backcolor begincolor endcolor supersample)
  196.  
  197.  
  198.     (while (<= Xindex xtiles)
  199.       (while (<= Yindex ytiles)
  200.         (if (= (rand 2) 0)
  201.             (use-tile img layer-one height width tile
  202.                       tiledraw1 (* Xindex size) (* Yindex size))
  203.             (use-tile img layer-one height width tile
  204.                       tiledraw2 (* Xindex size) (* Yindex size))
  205.         )
  206.         (set! Yindex (+ Yindex 1))
  207.       )
  208.       (set! Yindex 0)
  209.       (set! Xindex (+ Xindex 1))
  210.     )
  211.  
  212.     (gimp-image-delete tile)
  213.     (gimp-image-undo-enable img)
  214.     (gimp-display-new img)
  215.  
  216.     (gimp-context-pop)
  217.   )
  218. )
  219.  
  220. (script-fu-register "script-fu-3dtruchet"
  221.   _"3_D Truchet..."
  222.   _"Create an image filled with a 3D Truchet pattern"
  223.   "Adrian Likins <aklikins@eos.ncsu.edu>"
  224.   "Adrian Likins"
  225.   "1997"
  226.   ""
  227.   SF-ADJUSTMENT _"Block size"        '(64 5 1000 1 10 0 1)
  228.   SF-ADJUSTMENT _"Thickness"         '(12 2 100 1 10 0 1)
  229.   SF-COLOR      _"Background color"  "white"
  230.   SF-COLOR      _"Start blend"       "black"
  231.   SF-COLOR      _"End blend"         "white"
  232.   SF-TOGGLE     _"Supersample"       TRUE
  233.   SF-ADJUSTMENT _"Number of X tiles" '(5 1 1000 1 10 0 1)
  234.   SF-ADJUSTMENT _"Number of Y tiles" '(5 1 1000 1 10 0 1)
  235. )
  236.  
  237. (script-fu-menu-register "script-fu-3dtruchet"
  238.                          "<Image>/File/Create/Patterns")
  239.